package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.constant.SchemeType;
import org.jsola.hr.dto.SocProgAddDTO;
import org.jsola.hr.dto.SocProgUpdateDTO;
import org.jsola.hr.entity.SocProgDO;
import org.jsola.hr.query.SocProgQuery;
import org.jsola.hr.service.ISocProgService;
import org.jsola.hr.vo.SocProgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 参保方案表
 *
 * @author zhr
 */
@Component
public class SocProgTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISocProgService socProgService;

    /**
     * 生成add测试数据
     * @return SocProgAddDTO
     */
    public SocProgAddDTO getSocProgAddDTO(){
        SocProgAddDTO socProgAddDTO = new SocProgAddDTO();
        socProgAddDTO.setDeductionsDate(SafeKit.getInteger(getRandomValue("int",2)));
        socProgAddDTO.setType(SchemeType.SOC.getValue());
        socProgAddDTO.setServiceCost(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        socProgAddDTO.setProgName(getRandomValue("varchar",255));
        socProgAddDTO.setSourceId(getRandomValue("varchar",32));
        socProgAddDTO.setSocCity(getRandomValue("varchar",255));
        socProgAddDTO.setSocCityName(getRandomValue("varchar",255));
        socProgAddDTO.setOnlySocAmount(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socProgAddDTO.setPayProvidentFund(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        socProgAddDTO.setCompanyId(getRandomValue("varchar",32));
        socProgAddDTO.setSocTemplateId(getRandomValue("varchar",32));
        socProgAddDTO.setMeTemplateId(getRandomValue("varchar",32));
        socProgAddDTO.setPfTemplateId(getRandomValue("varchar",32));
        socProgAddDTO.setSocAccount(getRandomValue("varchar",50));
        socProgAddDTO.setMeAccount(getRandomValue("varchar",50));
        socProgAddDTO.setPfAccount(getRandomValue("varchar",50));
        socProgAddDTO.setIssue(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return socProgAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SocProgUpdateDTO
     */
    public SocProgUpdateDTO getSocProgUpdateDTO(SocProgVO socProgVO){
        return socProgService.selectDOById(socProgVO.getId(), SITE_ID).to(SocProgUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SocProgQuery
     */
    public SocProgQuery getSocProgQuery() {
        SocProgQuery socProgQuery = new SocProgQuery();
        List<SocProgDO> socProgDOList = socProgService.list(new SocProgDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(socProgDOList)) {
            SocProgDO socProgDO = socProgDOList.get(0);
            socProgQuery = socProgDO.to(SocProgQuery.class);
        }
        return socProgQuery;
    }

    /**
     * 保存示例
     * @return SocProgVO
     */
    public SocProgVO saveSocProgExample(){
        SocProgAddDTO addDTO = this.getSocProgAddDTO();
        SocProgVO socProgVO = socProgService.save(addDTO,buildTokenUser());
        return socProgVO;
    }


}

